package com.zghhost.stockweb.util;

import java.util.Calendar;
import java.util.Date;

/**
 * @author guohua.zhang@zhaopin.com.cn
 * @Date 2019/5/22 12:42
 */
public class DayUtil {
    public static Date[] dayWithoutWeekday(int lastN){
        Date[] res = new Date[lastN];
        Date d = new Date();
        Calendar c = Calendar.getInstance();
        int index=0,j=lastN;
        for(int i = 0;i < lastN;i++){
            Date day = DateUtil.addDate(d,Calendar.DATE,j-lastN);
            c.setTime(day);
            int weekday = c.get(Calendar.DAY_OF_WEEK);
            if(weekday >= 2 && weekday <=6){
                res[index++] = day;
            }else {
                i--;
            }
            j--;
        }
        return res;
    }

    public static void main(String[] args){
        Date[] ds = dayWithoutWeekday(5);
        for(Date d : ds){
            System.out.println(DateUtil.parseDateToStr(d,DateUtil.DATE_FORMAT_YYYYMMDD));
        }
    }

}
